package com.whynot.frame.manythread;

/**
 * Atomic模拟原子性。可以动态更改数据
 * 创建时间: 2018/12/24
 *
 */
public class AutomicThread extends Thread{
	private static int num = 0;
	//private static AtomicInteger num = new AtomicInteger(0);
	
	static void add(){
		for (int i = 0; i < 1000; i++) {
			num++;
			//num.incrementAndGet();
		}
		System.out.println("i="+num);
	}

	@Override
	public  void run() {
		add();
	}
		
	public static void main(String[] args) {
		AutomicThread[] t = new AutomicThread[10];
		
		for(int i = 0; i < 10;i++){
			t[i] = new AutomicThread();
		}
		
		for (int i = 0; i < t.length; i++) {
			t[i].start();
		}
		
	}
	
}
